import maxios from '../maxios'
class commonServe {
  // 登录
  login(params) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `user/login`,
        params,
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 修改密码
  changePassword(id, params) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `user/modifyPsw/${id}`,
        params,
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }

  // 根据学生id查询学生信息
  getStudentInfo(id) {
    return new Promise((resolve, reject) => {
      maxios.get(
        `student/getById/${id}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 根据学生id查询一卡通信息
  getCardInfo(id) {
    return new Promise((resolve, reject) => {
      maxios.get(
        `card/cardInfo/${id}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 修改学生信息
  changeStudentInfo(params) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `student/modifyStudent`,
        params,
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }

  // 申请一卡通
  applyCampus(id) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `card/apply/${id}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 一卡通挂失
  lostCard(id, params) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `card/loseCard/${id}`,
        params,
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 一卡通充值
  chargeCard(id, amount) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `card/cardcharge/${id}/${amount}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 水电网费充值
  chargeNetOrWater(id, amount, room) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `bill/charge/${id}/${amount}/${room}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 根据id查询账单
  getBill(id) {
    return new Promise((resolve, reject) => {
      maxios.get(
        `bill/getBill/${id}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 根据id查询充值记录
  getChargeBill(id) {
    return new Promise((resolve, reject) => {
      maxios.get(
        `card/getCardCharge/${id}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }

  // 餐超消费
  consumeInCanteenOrSuperMarket(id, amount, tag) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `bill/consume/${id}/${amount}/${tag}`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 反馈建议
  commitSuggestion(id, params) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `advice/addAdvice/${id}`,
        params,
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 获取服务器新闻资源
  getNewsList() {
    return new Promise((resolve, reject) => {
      maxios.post(
        `news/getAllNews`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  // 获取规章制度
  getAllRegularList() {
    return new Promise((resolve, reject) => {
      maxios.post(
        `regular/getAllRegular`,
        {},
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
  //上传图片
  uploadAvatar(params) {
    return new Promise((resolve, reject) => {
      maxios.post(
        `student/fileoss`,
        params,
        (res) => {
          resolve(res)
        },
        (err) => {
          reject(err)
        }
      )
    })
  }
}

export default new commonServe()
